<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2019/12/29
  Time: 8:59
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link type="text/css" href="../layui/css/layui.css" rel="stylesheet">
    <script type="text/javascript" src="../layui/layui.js"></script>
<script type="text/javascript">


        var tableIns;
        var form;
        var laydate;
        var index;
        var two;

        layui.use(
                [ 'table', 'form', 'element', 'form', 'layer', 'laydate' ],
                function() {
                    var table = layui.table;
                    var element = layui.element, layer = layui.layer;
                    laydate = layui.laydate;
                    form = layui.form;

                    tableIns = table
                        .render({
                            elem : '#dg',
                            url : $webURI
                                + "/protal/sourceno/foundNowSource.action",
                            limit : 10,
                            where : {
                                centerid : centerid
                            },
                            cols : [ [ // 表头
                                {
                                    field : 'sunday',
                                    title : '日',
                                    width : "14.29%",
                                    event : 'setsunday',
                                    style : 'height:100px;text-align:center;',
                                    templet : function(row) {

                                        if (row.sunday != null) {
                                            var date = row.sunday.numDate
                                                .substr(
                                                    8,
                                                    row.sunday.numDate.length);
                                            if (row.sunday.isDisable == '1') {
                                                return date
                                                    + "<div class=\"xz_tsbz\">休</div>";
                                            } else if (row.sunday.periodState == '2') {

                                                return date
                                                    + "<div class=\"xz_tsbz\">"
                                                    + row.sunday.timeName
                                                    + "</div>";
                                            } else {
                                                return date;
                                            }
                                        } else {
                                            return "";
                                        }
                                    }
                                },
                                {
                                    field : 'monday',
                                    title : '一',
                                    width : "14.29%",
                                    event : 'setmonday',
                                    style : 'height:100px;text-align:center;',
                                    templet : function(row) {
                                        if (row.monday != null) {
                                            var date = row.monday.numDate
                                                .substr(
                                                    8,
                                                    row.monday.numDate.length);

                                            if (row.monday.isDisable == '1') {
                                                return date
                                                    + "<div class=\"xz_tsbz\">休</div>";
                                            } else if (row.monday.periodState == '2') {

                                                return date
                                                    + "<div class=\"xz_tsbz\">"
                                                    + row.monday.timeName
                                                    + "</div>";
                                            } else {
                                                return date;
                                            }

                                        } else {
                                            return "";
                                        }
                                    }
                                },
                                {
                                    field : 'tuesday',
                                    title : '二',
                                    width : "14.29%",
                                    event : 'settuesday',
                                    style : 'height:100px;text-align:center;',
                                    templet : function(row) {
                                        if (row.tuesday != null) {
                                            var date = row.tuesday.numDate
                                                .substr(
                                                    8,
                                                    row.tuesday.numDate.length);
                                            if (row.tuesday.isDisable == '1') {
                                                return date
                                                    + "<div class=\"xz_tsbz\">休</div>";
                                            } else if (row.tuesday.periodState == '2') {

                                                return date
                                                    + "<div class=\"xz_tsbz\">"
                                                    + row.tuesday.timeName
                                                    + "</div>";
                                            } else {
                                                return date;
                                            }
                                        } else {
                                            return "";
                                        }
                                    }
                                },
                                {
                                    field : 'wednesday',
                                    title : '三',
                                    width : "14.29%",
                                    event : 'setwednesday',
                                    style : 'height:100px;text-align:center;',
                                    templet : function(row) {
                                        if (row.wednesday != null) {
                                            var date = row.wednesday.numDate
                                                .substr(
                                                    8,
                                                    row.wednesday.numDate.length);
                                            if (row.wednesday.isDisable == '1') {
                                                return date
                                                    + "<div class=\"xz_tsbz\">休</div>";
                                            } else if (row.wednesday.periodState == '2') {

                                                return date
                                                    + "<div class=\"xz_tsbz\">"
                                                    + row.wednesday.timeName
                                                    + "</div>";
                                            } else {
                                                return date;
                                            }
                                        } else {
                                            return "";
                                        }
                                    }
                                },
                                {
                                    field : 'thursday',
                                    title : '四',
                                    width : "14.29%",
                                    event : 'setthursday',
                                    style : 'height:100px;text-align:center;',
                                    templet : function(row) {
                                        if (row.thursday != null) {
                                            var date = row.thursday.numDate
                                                .substr(
                                                    8,
                                                    row.thursday.numDate.length);
                                            if (row.thursday.isDisable == '1') {
                                                return date
                                                    + "<div class=\"xz_tsbz\">休</div>";
                                            } else if (row.thursday.periodState == '2') {

                                                return date
                                                    + "<div class=\"xz_tsbz\">"
                                                    + row.thursday.timeName
                                                    + "</div>";
                                            } else {
                                                return date;
                                            }
                                        } else {
                                            return "";
                                        }
                                    }
                                },
                                {
                                    field : 'friday',
                                    title : '五',
                                    width : "14.29%",
                                    event : 'setfriday',
                                    style : 'height:100px;text-align:center;',
                                    templet : function(row) {
                                        if (row.friday != null) {
                                            var date = row.friday.numDate
                                                .substr(
                                                    8,
                                                    row.friday.numDate.length);
                                            if (row.friday.isDisable == '1') {
                                                return date
                                                    + "<div class=\"xz_tsbz\">休</div>";
                                            } else if (row.friday.periodState == '2') {

                                                return date
                                                    + "<div class=\"xz_tsbz\">"
                                                    + row.friday.timeName
                                                    + "</div>";
                                            } else {
                                                return date;
                                            }

                                        } else {
                                            return "";
                                        }
                                    }
                                },
                                {
                                    field : 'saturday',
                                    title : '六',
                                    width : "14.7%",
                                    event : 'setsaturday',
                                    style : 'height:100px;text-align:center;line-height:80px;',
                                    templet : function(row) {
                                        if (row.saturday != null) {
                                            var date = row.saturday.numDate
                                                .substr(
                                                    8,
                                                    row.saturday.numDate.length);
                                            // console.log(row.saturday);
                                            if (row.saturday.isDisable == '1') {
                                                return date
                                                    + "<div class=\"xz_tsbz\">休</div>";
                                            } else if (row.saturday.periodState == '2') {

                                                return date
                                                    + "<div class=\"xz_tsbz\">"
                                                    + row.saturday.timeName
                                                    + "</div>";
                                            } else {
                                                return date;
                                            }

                                        } else {
                                            return "";
                                        }
                                    }
                                } ] ],
                            done : function(res, curr, count) {

                                var now = $(".date").html();
                                var d = new Date(Date.parse(now));
                                var t = new Date();
                                var year = t.getFullYear();
                                var month = t.getMonth() + 1;
                                var mydate = (year.toString() + "-" + month
                                    .toString());

                                var date = new Date(Date.parse(mydate));
                                if (d < date) {

                                    return;
                                } else {

                                }

                                if (qx == 1 || sys == 0) {

                                    if (res.data.length == 0) {
                                        layer
                                            .confirm(
                                                '该中心当月还有没有生成号源，是否一键生成？',
                                                {
                                                    title : "提示",
                                                    icon : 7,
                                                    btn : [ '确定',
                                                        '取消' ]
                                                },
                                                function() {
                                                    /*
                                                     * layer.msg("正在生成", {
                                                     * time : 50000,
                                                     * icon : 16 });
                                                     */
                                                    form
                                                        .val(
                                                            "sourceno2",
                                                            {
                                                                "timeTypeId" : '',
                                                                "centerid" : centerid

                                                            })
                                                    two = layer
                                                        .open({
                                                            title : '时段类型', // 标题
                                                            type : 1,
                                                            area : [
                                                                '520px',
                                                                '400px' ],
                                                            shadeClose : false, // 点击遮罩关闭
                                                            content : $('.tongyong'),
                                                            skin : 'pop-class'
                                                        });

                                                });
                                    }
                                }

                            }
                        });

                    // 执行一个laydate实例
                    laydate.render({
                        elem : '#date' // 指定元素
                    });

                    $("th").css("text-align", "center");
                    $(".xz_tsbz").css("margin-top", "-10px");
                    $("table").addClass("xz_align_center");

                    // 标配单击监听
                    table.on('tool(Event)', function(obj) {

                        console.log(obj);

                        var data = obj.data;
                        //
                        if (qx == 1 || sys == 0) {
                            if (obj.event == 'setsaturday') {

                                var s = data.saturday;
                                if (s.numDate == null || s.numDate == "") {
                                    return;
                                }
                                var typeid;
                                if (s.periodState == "2") {
                                    typeid = s.timeTypeId;
                                } else {

                                    typeid = "";
                                }
                                form.val("sourceno", {
                                    "id" : s.id,
                                    "timeTypeId" : typeid,
                                    "date" : s.numDate
                                })

                            }
                            if (obj.event == 'setfriday') {

                                var s = data.friday;
                                if (s.numDate == null || s.numDate == "") {
                                    return;
                                }
                                var typeid;
                                if (s.periodState == "2") {
                                    typeid = s.timeTypeId;
                                } else {

                                    typeid = "";
                                }
                                form.val("sourceno", {
                                    "id" : s.id,
                                    "timeTypeId" : typeid,
                                    "date" : s.numDate
                                })

                            }
                            if (obj.event == 'setthursday') {

                                var s = data.thursday;
                                if (s.numDate == null || s.numDate == "") {
                                    return;
                                }
                                var typeid;
                                if (s.periodState == "2") {
                                    typeid = s.timeTypeId;
                                } else {

                                    typeid = "";
                                }
                                form.val("sourceno", {
                                    "id" : s.id,
                                    "timeTypeId" : typeid,
                                    "date" : s.numDate
                                })

                            }
                            if (obj.event == 'setwednesday') {

                                var s = data.wednesday;
                                if (s.numDate == null || s.numDate == "") {
                                    return;
                                }
                                var typeid;
                                if (s.periodState == "2") {
                                    typeid = s.timeTypeId;
                                } else {

                                    typeid = "";
                                }
                                form.val("sourceno", {
                                    "id" : s.id,
                                    "timeTypeId" : typeid,
                                    "date" : s.numDate
                                })

                            }
                            if (obj.event == 'settuesday') {

                                var s = data.tuesday;
                                if (s.numDate == null || s.numDate == "") {
                                    return;
                                }
                                var typeid;
                                if (s.periodState == "2") {
                                    typeid = s.timeTypeId;
                                } else {

                                    typeid = "";
                                }
                                form.val("sourceno", {
                                    "id" : s.id,
                                    "timeTypeId" : typeid,
                                    "date" : s.numDate
                                })

                            }
                            if (obj.event == 'setmonday') {

                                var s = data.monday;
                                if (s.numDate == null || s.numDate == "") {
                                    return;
                                }
                                var typeid;
                                if (s.periodState == "2") {
                                    typeid = s.timeTypeId;
                                } else {

                                    typeid = "";
                                }
                                form.val("sourceno", {
                                    "id" : s.id,
                                    "timeTypeId" : typeid,
                                    "date" : s.numDate
                                })

                            }
                            if (obj.event == 'setsunday') {

                                var s = data.sunday;
                                if (s.numDate == null || s.numDate == "") {
                                    return;
                                }
                                var typeid;
                                if (s.periodState == "2") {
                                    typeid = s.timeTypeId;

                                } else {

                                    typeid = "";
                                }

                                form.val("sourceno", {
                                    "id" : s.id,
                                    "timeTypeId" : typeid,
                                    "date" : s.numDate

                                })

                            }

                            index = layer.open({
                                title : '时段类型', // 标题
                                type : 1,
                                area : [ '520px', '400px' ],
                                shadeClose : false, // 点击遮罩关闭
                                content : $('.czmm-pop'),
                                skin : 'pop-class'
                            });
                            $("#timeTypeId").focus();

                        }
                    });

                    // 表单监听
                    form.on(("submit(submit)"), function(data) {
                        var param = {};
                        param = data.field;
                        param.centerid = centerid;
                        console.log(11111);
                        console.log(param);
                        // 单独修改特殊类型
                        $.ajax({
                            url : $webURI
                                + "/protal/sourceno/updateTimeType.action",
                            type : 'post',
                            dataType : 'text',
                            data : param,
                            success : function(d) {
                                if (d > 0) {
                                    layer.msg("成功！", {
                                        time : 1000,
                                        icon : 6
                                    });
                                } else if (d == "") {
                                    layer.msg("该类型没有设置时间段！请设置时间段再来操作！", {
                                        time : 1000,
                                        icon : 6
                                    });
                                } else {
                                    layer.msg("失败！", {
                                        time : 1000,
                                        icon : 5
                                    });
                                }
                                layer.close(index);
                                tableIns.reload({});
                                $("table").addClass("xz_align_center");

                            }

                        });

                        return false;
                    });

                    // 表单监听
                    form.on(("submit(submit2)"), function(data) {
                        var param = {};
                        param = data.field;

                        console.log(param);

                        // 一键生成
                        $.ajax({
                            url : $webURI
                                + "/protal/sourceno/insertOrUpdate.action",
                            type : 'post',
                            dataType : 'text',
                            data : param,
                            success : function(d) {
                                if (d > 0) {
                                    layer.msg("成功", {
                                        time : 1000,
                                        icon : 6
                                    });
                                    layer.close(two);
                                    tableIns.reload({});
                                    $("table").addClass("xz_align_center");
                                } else if (d == -5) {
                                    layer.msg("该时段类型下没有设置详细时段号源！请设置后再来一键生成！", {
                                        time : 1000,
                                        icon : 6
                                    });
                                    layer.close(two);
                                } else {
                                    layer.msg("系统错误", {
                                        time : 1000,
                                        icon : 6
                                    });
                                    layer.close(two);
                                }

                            }

                        });

                        return false;
                    });

                });

// 字符串转日期格式，strDate要转为日期格式的字符串
        function getDate(strDate) {
            var date = eval('new Date('
                + strDate.replace(/\d+(?=-[^-]+$)/, function(a) {
                    return parseInt(a, 10) - 1;
                }).match(/\d+/g) + ')');

        }

// 去除周末
        function deleteWeek() {
            var date = $(".date").html();

            $.ajax({
                url : $webURI + '/protal/sourceno/removeWeek.action',
                type : 'post',
                dataType : 'text',
                data : {
                    strdate : date,
                    centerid : centerid
                },
                success : function(d) {
                    layer.msg(d, {
                        time : 1000
                    });
                    tableIns.reload({});
                    $("table").addClass("xz_align_center");
                }
            })
        }

        function deleteHoliday() {
            var date = $(".date").html();
            $.ajax({
                url : $webURI + '/protal/sourceno/removeHoliday.action',
                type : 'post',
                dataType : 'text',
                data : {
                    strdate : date,
                    centerid : centerid
                },
                success : function(d) {
                    layer.msg(d, {
                        time : 1000
                    });
                    tableIns.reload({});
                    $("table").addClass("xz_align_center");
                }
            })
        }

        function right() {
            var now = $(".date").html();
            var d = new Date(now.replace(/-/g, "/"));
            d.setMonth(d.getMonth() + 1);
            var str = d.getFullYear() + "-"
                + (d.getMonth() >= 9 ? d.getMonth() + 1 : "0" + (d.getMonth() + 1));
            $(".date").html(str);
            $("#strdate").val(str);
            tableIns.reload({
                where : {
                    strdate : str,
                    centerid : centerid
                }
            });
            $("table").addClass("xz_align_center");
        }
        function left() {

            var now = $(".date").html();
            var d = new Date(now.replace(/-/g, "/"));
            d.setMonth(d.getMonth() - 1);
            var str = d.getFullYear() + "-"
                + (d.getMonth() >= 9 ? d.getMonth() + 1 : "0" + (d.getMonth() + 1));
            $(".date").html(str);
            $("#strdate").val(str);
            tableIns.reload({
                where : {
                    strdate : str,
                    centerid : centerid
                }
            });
            $("table").addClass("xz_align_center");
        }




</script>
</head>
<body>

<%--<span id="testView"></span>--%>
<div id="test2"></div>


<!--//添加表单-->
<form class="layui-form" style="display: none;" id="addform" lay-filter="formFilter"> <!-- 提示：如果你不想用form，你可以换成div等任何一个普通元素 -->
    <div class="layui-form-item">
        <label class="layui-form-label">主题:</label>
        <div class="layui-inline">
            <input type="text" name="name" lay-verify="required" placeholder="请输入便签标题"  class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">时间段:</label>
        <div class="layui-inline">
            <input type="date" name="datestart" lay-verify="required"   class="layui-input">--
            <input type="date" name="dateend" lay-verify="required"   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">类型</label>
        <div class="layui-inline">
            <input type="radio" name="type" value="0" title="工作事务">
            <input type="radio" name="type" value="1" title="个人事务" checked>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">地点:</label>
        <div class="layui-inline">
            <input type="text" name="location" lay-verify="required" placeholder="请输入便签标题"  class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">预约他人</label>
        <div class="layui-inline">
            <select name="interest" lay-filter="userId">
                <option value="0">写作</option>
                <option value="1">阅读</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">内容:</label>
        <div class="layui-inline">
            <textarea name="content" placeholder="请输入内容" class="layui-textarea"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">是否公开:</label>
        <div class="layui-inline">
            <input type="radio" name="isOpen" value="0" title="是">
            <input type="radio" name="isOpen" value="1" title="否" checked>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">部门日程:</label>
        <div class="layui-inline">
            <input type="radio" name="isDept" value="0" title="是">
            <input type="radio" name="isDept" value="1" title="否" checked>
        </div>
        (如果为部门领导身份)
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="submitFilter">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
    <!-- 更多表单结构排版请移步文档左侧【页面元素-表单】一项阅览 -->
</form>
</body>
</html>
